package de.zinulla.moviethek.viewbinder;

import android.database.Cursor;
import android.graphics.BitmapFactory;
import android.support.v4.widget.SimpleCursorAdapter.ViewBinder;
import android.view.View;
import android.widget.ImageView;
import de.zinulla.common.MoviethekConstants;
import de.zinulla.moviethek.R;

public class MovieArrayViewBinder implements ViewBinder {

	@Override
	public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
		if (view instanceof ImageView) {
			if (columnIndex == 1) {
				ImageView image = (ImageView) view;
				byte[] byteArr = cursor.getBlob(columnIndex);
				image.setImageBitmap(BitmapFactory.decodeByteArray(byteArr, 0, byteArr.length));
				return true;
			}
			if (columnIndex == 4) {
				ImageView image = (ImageView) view;
				String media = cursor.getString(columnIndex);
				if (media.equals(MoviethekConstants.MEDIA_BR)) {
					image.setImageResource(R.drawable.bluray);
					return true;
				} else if (media.equals(MoviethekConstants.MEDIA_BR_3D)) {
					image.setImageResource(R.drawable.bluray3d);
					return true;
				} else if (media.equals(MoviethekConstants.MEDIA_DVD)) {
					image.setImageResource(R.drawable.dvd);
					return true;
				}

			}
		}
		// if (view instanceof ImageView && columnIndex ==
		// MovieDataSource.COLUMN_MEDIA){
		// ImageView image = (ImageView) view;
		// String media = cursor.getString(columnIndex);
		// if (media.equals(MyMovieConstants.MEDIA_BR)){
		// image.setImageResource(R.drawable.bluray);
		// } else {
		// image.setImageResource(R.drawable.dvd);
		// }
		// return true;
		// }
		return false;
	}

}